package com.qupeng.demo.kafka.kafkaspringbootstreams.common.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public final class TimeUtils {
    private TimeUtils() {}

    public static String format(long timestamp) {
        return buildSimpleDateFormat().format(new Date(timestamp));
    }

    public static long parse(String formattedTime) throws ParseException {
        return buildSimpleDateFormat().parse(formattedTime).getTime();
    }

    public static SimpleDateFormat buildSimpleDateFormat() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        sdf.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
        return sdf;
    }
}
